package cn.xfdzx.android.apps.shop.fragment;

import android.app.Dialog;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.fragment.app.Fragment;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.util.ImageGlideUtil;


/**
 * Created by zf on 2020/9/18.
 */
public class BigImage_Fragment extends Fragment {

    private View view;
    private int flag;
    private int countsize;
    private String url;
    private long clickTime;
    private ImageView img;
    private ImageView img_share;
    private int firstClick = 0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        Bundle bundle = this.getArguments();
        if (bundle != null) {
            flag = bundle.getInt("flag");
            countsize=bundle.getInt("countsize");
            url=bundle.getString("url");

        }
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // TODO Auto-generated method stub

        if (view != null) {
            ViewGroup parent = (ViewGroup) view.getParent();
            if (parent != null) {
                parent.removeView(view);
            }
            return view;
        } else {
        }
        view = inflater.inflate(R.layout.fragment_bigimg, container, false);

        TextView tv= (TextView) view.findViewById(R.id.bigimg_tv);
        tv.setText((flag+1)+"/"+(countsize));
        img = (ImageView) view.findViewById(R.id.bigimg_img);
            if (url.contains(".gif")) {
//                Glide.with(getActivity()).load(url).
//                        asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(img);
            } else {
                ImageGlideUtil.loadImage(getActivity(), img,url);
//                Glide.with(getActivity())
//                        .load(url)
//                        .placeholder(R.color.c_f5f5f5)
//                        .into(img);
            }
        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                getActivity().finish();
            }
        });
        return view;
    }

    public static BigImage_Fragment newInstance(int flag, int countsize, String url) {
        Bundle bundle = new Bundle();
        bundle.putInt("flag", flag);
        bundle.putInt("countsize",countsize);
        bundle.putString("url",url);

        BigImage_Fragment testFm = new BigImage_Fragment();
        testFm.setArguments(bundle);
        return testFm;

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}
